#! /bin/sh

ERL_CRASH_DUMP=${ERL_CRASH_DUMP-/dev/null}
export ERL_CRASH_DUMP

# This file tests true/true/false and true/true/true.

# There are basically 6 tests:
# 
# existing directory      reuse_schema    external_db_nodes
# false                   false           false
# false                   true            false
# true                    false           false
# true                    false           true
# true                    true            false
# true                    true            true
# 
# NB: false/false/true is not possible so not tested.
#     false/true/true is not possible so not tested.

rm -rf Mnesia*

{
erl -pa ../src -sname schemafinder_test1 -s combonodefinder -eval '
  { ok, [ App ] } = file:consult ("../src/schemafinder.app"),
  ok = application:load (App),
  application:set_env (schemafinder, reuse_schema, true),
  application:set_env (schemafinder, save_schema, true),
  application:set_env (schemafinder, foreign_key_bugfix, false),
  schemafinder:start (),
  { atomic, ok } = mnesia:create_table (flass, []),
  Self = node (),
  [ Self ] = mnesia:table_info (flass, active_replicas)
' -noshell -noinput -s init stop

test -d Mnesia.schemafinder_test1* || exit 1

erl -pa ../src -sname schemafinder_test1 -s combonodefinder -eval '
  { ok, [ App ] } = file:consult ("../src/schemafinder.app"),
  ok = application:load (App),
  application:set_env (schemafinder, reuse_schema, true),
  application:set_env (schemafinder, save_schema, false),
  application:set_env (schemafinder, foreign_key_bugfix, false),
  schemafinder:start (),
  Self = node (),
  [ Self ] = mnesia:table_info (flass, active_replicas)
' -noshell -noinput -s init stop || exit 1

test -d Mnesia.schemafinder_test1* && exit 1
} > test-schemafinder-ttf.out

rm -rf Mnesia*

exit 0
